#include <stdio.h>
#include <string.h>

// DJB2算法
unsigned int djb2(const char *str) {
    unsigned int hash = 5381;
    int c;

    while ((c = *str++)) {
        hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
    }

    return hash;
}

// SDBM算法
unsigned int sdbm(const char *str) {
    unsigned int hash = 0;
    int c;

    while ((c = *str++)) {
        hash = c + (hash << 6) + (hash << 16) - hash;
    }

    return hash;
}

int main() {
    const char *test_string1 = "Hello, World!";
	const char *test_string2 = "Hello, Worle!";


    printf("DJB2 Hash: %08x\n", djb2(test_string1));
    printf("DJB2 Hash: %08x\n", djb2(test_string2));
	
	printf("SDBM Hash: %08x\n", sdbm(test_string1));
    printf("SDBM Hash: %08x\n", sdbm(test_string2));
    return 0;
}    